package com.yantong.service.impl;

import com.yantong.mapper.TourNumberMapper;
import com.yantong.pojo.TourNumber;
import com.yantong.service.TourNumberService;
import com.yantong.utils.PageUtils;
import com.yantong.utils.ValidateUtil;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class TourNumberServiceImpl implements TourNumberService {
    @Autowired
    private TourNumberMapper tourNumberMapper;

    @Override
    public PageUtils<TourNumber> tourNumberlist(Long centreId, Long teamId, Integer status, Integer offset, Integer limit) {
        PageUtils<TourNumber> pageUtils = new PageUtils<>();
        Map<String, Object> params = new HashMap<String, Object>();
        if (ValidateUtil.isNotEmptyObjectOrString(centreId)){
            params.put("centreId",centreId);
        }
        if (ValidateUtil.isNotEmptyObjectOrString(teamId)){
            params.put("teamId",teamId);
        }
        if (ValidateUtil.isNotEmptyObjectOrString(status)){
            params.put("status",status);
        }
        if (ValidateUtil.isEmptyObjectOrString(offset)){
            offset = 0;
        }
        if (ValidateUtil.isEmptyObjectOrString(limit)){
            limit = 10;
        }
        int total = tourNumberMapper.countByParams(params);
        if (total > 0) {
            pageUtils.setTotal(total);
            pageUtils.setRows(tourNumberMapper.listByParams(params, new RowBounds(offset, limit)));
        }
        return pageUtils;
    }

    @Override
    public int remove(Long id) {
        if (id == null) {
            return 0;
        }
        return tourNumberMapper.deleteByPrimaryKey(id);
    }
}
